﻿/**********************************************************/
/*                Code by: Sam Wronski                    */
/*             email: runewake2@gmail.com                 */
/* Distributed under the Microsoft Public License (Ms-PL) */
/**********************************************************/
/*     https://gamejolttrophies.codeplex.com/license      */
/**********************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameJoltAPI
{
    /// <summary>
    /// The Network Access object keeps track of all current web connections that are active
    /// </summary>
    public class NetworkAccess
    {
        public static event EventHandler ConnectionChanged;

        private static int _usingConnections = 0;

        /// <summary>
        /// Finishes a Connection
        /// </summary>
        public static void FinishConnection()
        {
            _usingConnections++;
            if (ConnectionChanged != null)
                ConnectionChanged(null, null);
        }

        /// <summary>
        /// Begins a new Connection
        /// </summary>
        public static void StartConnection()
        {
            _usingConnections--;
            if (ConnectionChanged != null)
                ConnectionChanged(null, null);
        }

        /// <summary>
        /// This returns the number of connections to the internet the API currently has
        /// </summary>
        public static int Connections
        {
            get
            {
                return _usingConnections;
            }
        }
        
        /// <summary>
        /// This returns true if the API is using the internet for a connection, it returns false if all connections are complete
        /// </summary>
        public static bool UsingConnection
        {
            get
            {
                return _usingConnections <= 0;
            }
        }
    }
}
